package metrics_sql

const (
	K8sContainerMemUsage = `
guid = "%v"
from(bucket: "data")
  |> range(start: %v, stop: %v)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "container_memory_usage_bytes")
  |> filter(fn: (r) => r["namespace"] == guid )
  |> filter(fn: (r) => r["container"] != "POD" and r["container"]!="")
  |> filter(fn: (r) => r["pod"] != "jaeger-glue")
  |> filter(fn: (r) => r["container"] != "linkerd-proxy")
  |> filter(fn: (r) => r["id"] =~ /^\/kubepods.*/)
  |> map(fn: (r) => ({_field:"memory_usage_bytes",_value:r._value,_time:r._time,instance:r["container"],limit:0}))
  |> window(every: inf)
`
	//	K8sContainerMemUsage = `
	//query = (start=%v,stop=%v,guid="%v") => {
	//  memory_usage_bytes = from(bucket: "data")
	//    |> range(start: start, stop: stop)
	//    |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
	//    |> filter(fn: (r) => r["_field"] == "container_memory_usage_bytes")
	//    |> filter(fn: (r) => r["namespace"] == guid )
	//    |> filter(fn: (r) => r["container"] != "POD" and r["container"]!="")
	//    |> filter(fn: (r) => r["pod"] != "jaeger-glue")
	//    |> filter(fn: (r) => r["id"] =~ /^\/kubepods.*/)
	//    |> map(fn: (r) => ({_field:"memory_usage_bytes",_value:r._value,_time:r._time,instance:r["container"]}))
	//    |> window(every: inf)
	//  memory_limit =from(bucket: "data")
	//    |> range(start: start, stop: stop)
	//    |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
	//    |> filter(fn: (r) => r["_field"] == "kube_pod_container_resource_limits")
	//    |> filter(fn: (r) => r["namespace"] == guid )
	//    |> filter(fn: (r) => r["resource"] == "memory")
	//    |> last()
	//    |> map(fn: (r) => ({_field:"memory_usage_bytes",_value:r._value,_time:r._time,instance:r["container"]}))
	//    |> window(every: inf)
	//    return join(tables: {memory_usage_bytes: memory_usage_bytes, memory_limit: memory_limit}, on: [ "_stop", "_start", "instance"])
	//    |> map(fn: (r) => ({_field:"node_memory_usage",_value: r._value_memory_usage_bytes /  r._value_memory_limit  ,_time:r._time_memory_usage_bytes,instance:r["instance"],limit: 1}))
	//}
	//
	//query()
	//`
	K8sContainerMemUsagelast = `
guid = "%v"
from(bucket: "data")
  |> range(start: %v, stop: %v)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "container_memory_usage_bytes")
  |> filter(fn: (r) => r["namespace"] == guid )
  |> filter(fn: (r) => r["container"] != "POD" and r["container"]!="")
  |> filter(fn: (r) => r["pod"] != "jaeger-glue")
  |> filter(fn: (r) => r["container"] != "linkerd-proxy")
  |> filter(fn: (r) => r["id"] =~ /^\/kubepods.*/)
  |> last()
  |> map(fn: (r) => ({_field:"memory_usage_bytes",_value:r._value,_time:r._time,instance:r["container"],limit:0}))
  |> window(every: inf)
`
	GluenetContainerMemUsage = `
guid = "%v"
service = "%v"
name = guid+"_"+service
size = %f

from(bucket: "data")
  |> range(start: %v, stop: %v)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "container_memory_usage_bytes")
  |> filter(fn: (r) => r["name"] == name)
  |> map(fn: (r) => ({_field:"cpu_usage",_value:r._value / size ,_time:r._time,instance:service,limit: 1.0}))
`
	GluenetContainerMemUsagelast = `
guid = "%v"
service = "%v"
name = guid+"_"+service
size = %f

from(bucket: "data")
  |> range(start: %v, stop: %v)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "container_memory_usage_bytes")
  |> filter(fn: (r) => r["name"] == name)
  |> last()
  |> map(fn: (r) => ({_field:"cpu_usage",_value:r._value / size ,_time:r._time,instance:service,limit: 1.0}))
`
)
